﻿using System;
using System.Linq;
using Prometheus.Binding.Core;
#if NETFX_CORE
using Windows.UI.Xaml;
#else
using System.Windows;
#endif



namespace Prometheus.Binding.ReadOnly
{
    /// <summary>
    /// Do not use it
    /// </summary>
    public class proReadOnlyForm : proFormBase
    {
        #region Binding setting

        /// <summary>
        /// Binds the control property to any path from datacontext
        /// </summary>
        internal new static void SetproBinding(FrameworkElement element, proBindingBase bindingBase)
        {
            if (bindingBase is proBindingCollection)
            {
                var bindingCollection = (proBindingCollection) bindingBase;
                foreach (proReadOnlyBinding @base in bindingCollection.Bindings)
                {
                    if (@base is proBindingCollection)
                        throw new InvalidOperationException(
                            "proBindingCollection can not contain another collection of type jBindingBase"); //btw why?
                    proFormBase.SetproBinding(element, @base);
                }
            }
            else
            {
                proFormBase.SetproBinding(element, bindingBase);
            }
        }

        /// <summary>
        /// Returns first binding of provided control
        /// </summary>
        internal new static proBindingBase GetproBinding(FrameworkElement element)
        {
            return proBindingBase.BoundControls.FirstOrDefault(b => b.Value == element).Key;
        }

        #endregion
    }
}